package net.gz01.wallet.web.service;

import java.text.DecimalFormat;

import com.alibaba.fastjson.JSONObject;

import lombok.extern.slf4j.Slf4j;
import net.gz01.util.ZOAliSms;
import net.gz01.wallet.web.config.SystemConfig;

@Slf4j
public class SendSMSConfig {
	
    public static final String SMS_PREFIX = "allInfo_";

    public static final String SMS_Name = "友利";
    public static final String SMS_Service = "0755-2759-5390";
    public static final String loginTempCode = "SMS_165850173";
    public static final String setPayPasswordCode="SMS_166095957";
    public static final String walletChargeCode="SMS_166095979";

    //收入： SMS_166370342
    //public static final String InwalletChargeCode="SMS_166370420";


    public static final String sms_accessKeyId = SystemConfig.config.get("sms_accessKeyId");
    public static final String sms_accessSecret =  SystemConfig.config.get("sms_accessSecret");

/*
模版内容:
尊敬的${user}用户，您的友利账户${todoamtShow}元，剩余余额${balance}元，请悉知，如有疑问，请拨打客服电话：${service}
变量属性:
user-其他号码；todoamtShow-其他；balance-其他；service-电话号码；
 */
    public static boolean sendSMSAddMenoy(String phoneNo, String amtShow, String balance){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("user", phoneNo);
        if(!amtShow.contains("￥")){
            amtShow = "￥"+ new DecimalFormat("#,##0.00").format((Long.parseLong(amtShow))/100.0);
        }

        if(!balance.contains("￥")){
            balance ="￥"+ new DecimalFormat("#,##0.00").format((Long.parseLong(balance))/100.0);
        }
        jsonObject.put("todoamtShow", "收入:"+ amtShow);
        jsonObject.put("balance", balance);
        jsonObject.put("service", SMS_Service);

        ZOAliSms zoAliSms = new ZOAliSms(sms_accessKeyId, sms_accessSecret);
        JSONObject result = zoAliSms.send(phoneNo, jsonObject.toJSONString(), SMS_Name, walletChargeCode);
        if ("OK".equals(result.getString("Code"))) {

        } else {
            log.error("短信发送失败-->" + phoneNo + ";" + amtShow + "金额加的短信返回--->" + result.toJSONString());
            return false;
        }
        return true;
    }

    public static boolean senSMSSubAmt(String phoneNo, String outAmt, String balance){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("user", phoneNo);
        if(!outAmt.contains("￥")){
            outAmt ="￥"+ new DecimalFormat("#,##0.00").format((Long.parseLong(outAmt))/100.0);
        }

        if(!balance.contains("￥")){
            balance = "￥"+ new DecimalFormat("#,##0.00").format((Long.parseLong(balance))/100.0);
        }
        jsonObject.put("todoamtShow", "支出:" + outAmt);
        jsonObject.put("balance", balance);
        jsonObject.put("service", SMS_Service);

        ZOAliSms zoAliSms = new ZOAliSms(sms_accessKeyId, sms_accessSecret);
        JSONObject result = zoAliSms.send(phoneNo, jsonObject.toJSONString(), SMS_Name, walletChargeCode);
        if ("OK".equals(result.getString("Code"))) {

        } else {
            log.error("短信发送失败-->" + phoneNo + ";" + outAmt + "金额加的短信返回--->" + result.toJSONString());
            return false;
        }
        return true;
    }

    public static void main(String args[]){
        SendSMSConfig.senSMSSubAmt("15975508712", "212102", "3456105");
    }

}
